package com.example.administrator.yuejian35.Find.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.yuejian35.Config;
import com.example.administrator.yuejian35.Find.bean.Comment;
import com.example.administrator.yuejian35.R;
import com.example.administrator.yuejian35.button.ShineButton;
import com.squareup.picasso.Picasso;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by JUSTIN on 2017/10/15.
 */

public class CommentAdapter extends BaseAdapter {

    private LayoutInflater mInflater;

    private List<Comment> list;
    private Context context;

    public CommentAdapter(List<Comment> list, Context context) {

        this.mInflater = LayoutInflater.from(context);
        this.list = list;
        this.context=context;

    }

    public void setList(List<Comment> la){
        list=la;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        Comment comment = list.get(position);

        ViewHolder holder = null;
        if(view==null){
            view = mInflater.inflate(R.layout.item_comment, null);
            holder = new ViewHolder();

            view.setClickable(false);

			holder.uname = (TextView)view.findViewById(R.id.comm_uname);
			holder.content = (TextView)view.findViewById(R.id.comm_content);
			holder.time = (TextView)view.findViewById(R.id.comm_time);
            holder.hit = (TextView)view.findViewById(R.id.comm_hit);
            holder.hits = (ShineButton) view.findViewById(R.id.comm_btn_hit);

			holder.upic=(CircleImageView) view.findViewById(R.id.me_upic);
            view.setTag(holder);

        }
        else {
            holder = (ViewHolder) view.getTag();
        }

			holder.content.setText(comment.getContent());
            holder.uname.setText(comment.getUname());
            holder.time.setText(comment.getComtime());
            holder.hit.setText(comment.getCommhit());
            holder.hits = (ShineButton) view.findViewById(R.id.comm_btn_hit);
            Picasso.with(context)
                    .load(Config.CoachImages_URL+comment.getUserpic())
                    .into(holder.upic);



        return view;
    }

    public final class ViewHolder{

        public TextView uname;
        public TextView time;
        public TextView content;
        public TextView hit;
        public CircleImageView upic;
        public ShineButton hits;

    }
}
